/*
 * 		Author : Xerxes
 * 		Program: 
 * 		Created On : 01.10.2011 00:37:31 BDT
 *      "I have not failed, I have just found 10000 ways that won't work.
 * 
*/


#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstring>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define fo(i,st,ed) for(int i = st ; i < ed ; ++i )
#define foE(i,st,ed) for(int i = st ; i <= ed ; ++i )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip system("pause")
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define tp pair< int, pair<int,int> >
#define mmk( x, y , z ) mk( x, mk( y, z ) )

inline void wait( double seconds ){
    double endtime = clock()+( seconds* CLOCKS_PER_SEC );
    while( clock() < endtime ){
        ;
    }
}
int R,C;
char G[25][25];
int sr,sc;
inline void Read(){
	fo(i,0,R){
		fo(j,0,C){
			cin>>G[i][j];
			G[i][j+C]=G[i][j];
		}
	}
	scanf("%d %d",&sr,&sc);
}
char ch;
int r[]={-1,+0,+1,+0, -1,-1,+1,+1 };
int c[]={+0,+1,+0,-1, -1,+1,+1,-1 };
inline int colorit(int _r, int _c){
	stack< pair<int,int> > q;
	int res=1;
	q.push( mk(_r,_c) );
	G[_r][_c]='~';
	
	while( q.empty()==false ){
		pair<int,int> father = q.top();
		q.pop();
		
		fo(i,0,4){
			int tr = father.f+r[i];
			int tc = father.s+c[i];
			if( tr<0 || tr>=R )continue;
			if( tc<0 ){
				tc = C-1;
			}
			else if( tc>=C ){
				tc = 0;
			}
			if( G[tr][tc]==ch ){
				res+=1;
				G[tr][tc]='~';
				q.push( mk(tr,tc) );
			}
			
		}
	}
	
return res;	
}
string feed="";
inline void Proc(){
	ch = G[sr][sc];
	colorit(sr,sc);
	
	int best = 0;
	int prothom=1;
	/*
	fo(i,0,R){
		fo(j,0,C){
			cout<<G[i][j];
		}
		cout<<"\n";
	}
	cout<<"\n";
	*/ 
	fo(i,0,R){
		fo(j,0,C){
			if( G[i][j]==ch ){
				int var = colorit(i,j);
				if( prothom==1 ){
					best = var;
					prothom=0;
				}
				else{
					best = max(best, var);
				}
			}
		}
	}
	cout<<feed<<best<<"\n";
	//feed="\n";
	
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("in","rt",stdin);
        freopen("out","wt",stdout);
    #endif
    
	while( scanf("%d %d",&R,&C)==2 ){
		Read();
		Proc();
	} 
return 0;
}


